<template>
    <div class="common-layout">
        <!-- <el-container> -->
        <el-header class="el-header">
            <h2>车站设备维修五信息管理系统</h2>
            <div class="user-box">
                <el-icon>
                    <User />
                </el-icon>
                <div class="realname-box">{{ realname }}</div>
                <el-icon v-show="isDown" @click="realNameIconChang">
                    <ArrowDown />
                </el-icon>
                <el-icon v-show="isUp" @click="realNameIconChang">
                    <ArrowUp />
                </el-icon>
                <div v-show="lbpShow" class="logout-box-parent">
                    <div class="change-ps son">用户信息</div>
                    <div class="logout-box son" @click="logout">退出登录</div>
                </div>
            </div>
        </el-header>
        <el-container>
            <el-aside>
                <div class="menu-btn-box">
                    <div class="menu-box " :class="{active:isMenuActive}" @click="toggleMenu" title="菜单">
                        <el-icon><Menu /></el-icon>                        
                    </div>
                    <div class="favorites-box" :class="{active:isFavoritesActive}" @click="toggleFavorites" title="收藏">
                        <el-icon><Star /></el-icon>
                    </div>
                    <div class="search-box" :class="{active:isSearchActive}" @click="toggleSearch" title="搜索">
                        <el-icon><Search /></el-icon>
                    </div>
                </div>
                <div class="menu-info-box" v-show="isMenuActive">
                    <MenuList v-for="(item,i) in menuList" :key="i" :item="item"/>  
                </div>
                <div class="favorites-info-box" v-show="isFavoritesActive">
                    favorites
                </div>
                <div class="search-info-box" v-show="isSearchActive">
                    <el-input class="search-input" v-model="searchInput" placeholder="Please input" clearable/>
                    <div class="search-res">
                        search-res{{ searchInput }}
                    </div>
                </div>
            </el-aside>
            <el-main>
                <div class="tabs-box">
                    <Tabs/>
                </div>
                <div class="session-box">
                    <div class="home-session" :class="{show:useStore.homeIsShow}">
                    <Home/>
                    </div>
                    <div class="other-session" :class="{show:useStore.otherIsShow}">
                        <RouterView v-slot="{ Component }">
                            <KeepAlive>
                                <component :is="Component"></component>
                            </KeepAlive>
                        </RouterView>
                    </div>
                </div> 
            </el-main>
        </el-container>
    </div>
</template>

<script setup>
import { ref  } from 'vue'
import { mainStore } from '@/stores/store'
import { useRouter } from 'vue-router'
import { removeToken } from '@/utils/token'
import MenuList from '@/views/MenuList.vue'
import Tabs from '@/views/Tabs.vue'
import Home from '@/views/Home.vue'

const router = useRouter()
const useStore = mainStore()

let realname = useStore.userInfo.REALNAME
let isDown = ref(true)
let isUp = ref(false)
let lbpShow = ref(false)
let isMenuActive = ref(true)
let isFavoritesActive = ref(false)
let isSearchActive = ref(false)
let searchInput = ref(null)
let menuList = useStore.menuList

//切换user-box内的图标及展示已退出菜单
const realNameIconChang = () => {
    isDown.value = !isDown.value
    isUp.value = !isUp.value
    !isDown.value && isUp.value ? lbpShow.value = true : lbpShow.value = false
}

//切换菜单、收藏夹、搜索
const toggleMenu = ()=>{
    if(!isMenuActive.value){
        isMenuActive.value = true
        isFavoritesActive.value = false
        isSearchActive.value = false
    } 
}
const toggleFavorites = ()=>{
    if(!isFavoritesActive.value){
        isFavoritesActive.value = true
        isMenuActive.value = false
        isSearchActive.value = false
    } 
}
const toggleSearch = ()=>{
    if(!isSearchActive.value){
        isSearchActive.value = true
        isFavoritesActive.value = false
        isMenuActive.value = false
    } 
}

//退出登录
const logout = () => {
    removeToken()
    useStore.clearUserInfo()
    useStore.clearMenuList()
    useStore.clearAllSubTabList()
    useStore.clearPgs()
    useStore.toggleHomeShow('/xfjc/index/home')
    router.push("./login")
}



</script>

<style lang="less" scoped>
.common-layout {
    height: 100vh;
    width: 100vw;

    .el-header {
        background-color: #165bf0;
        color: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 6%;
        // border-bottom: #fff solid .0625rem;

        .user-box {
            position: relative;
            width: 6.25rem;
            display: flex;
            justify-content: space-around;
            align-items: center;

            .realname-box {
                font-size: .75rem;
            }

            .logout-box-parent {
                height: 3.125rem;
                width: 4.6875rem;
                border: #165bf0 solid .0625rem;
                background-color: #fff;
                position: absolute;
                top: 1.25rem;

                .son {
                    height: 50%;
                    line-height: 100%;
                    display: flex;
                    align-items: center;
                    /* 垂直居中 */
                    justify-content: center;
                    font-size: .75rem;
                    color: #165bf0;
                }

                .son:hover {
                    background-color: #5084f5;
                    color: #fff;
                    cursor: pointer;
                }
            }

            .el-icon:hover {
                cursor: pointer;
            }
        }
    }

    .el-container {
        height: 94%;

        .el-aside {
            // background-color: #3e6af8;
            height: 100%;
            width: 15%;

            border-right: #d9e1f1 solid .0625rem;
            .menu-btn-box {
                // background-color: aquamarine;
                height: 5%;
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: space-around;

                .menu-box,.favorites-box,.search-box {
                    height: 100%;
                    width: 33%;
                    display: flex;
                    align-items: center;
                    justify-content: space-evenly;

                    .el-icon {
                        font-size: 1.25rem;
                        color: #3f77ee;
                    }
                    .el-icon:hover {
                        font-size: 1.375rem;
                        cursor: pointer;
                    }
                }
                .menu-box.active,.favorites-box.active,.search-box.active {
                    background-color: #eff1f5;
                    // color: #165bf0;
                    .el-icon{
                        color: #165bf0;
                    }
                }                
            }

            .search-info-box,
            .favorites-info-box,
            .menu-info-box {
                height: 95%;
                width: 100%;
                overflow: auto;
            }

            .search-info-box{
                .search-input{
                    width: 80%;
                }
            }
        }
        .el-main{
            padding: 0;
            .tabs-box{
                height: 4%;
                width: 100%;
                border-bottom: #d9e1f1 solid .0625rem;
                display: flex;
            }
            .session-box{
                height: 96%;
                width: 100%;
            }
        }
    }
}
</style>